/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalUnit;

import static java.time.temporal.ChronoField.DAY_OF_MONTH;

/**
 * <p>Project: jse2204 - Time2
 * <p>Powered by webrx On 2022-08-31 14:59:43
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Time2 {
    public static void main(String[] args) {
        LocalDate now = LocalDate.now();
        now = LocalDate.of(now.getYear(),now.getMonth().getValue(),1);
        System.out.printf("%tF%n",now);

        LocalDate nn = LocalDate.of(2022,3,20);//求 2022,3,1
        System.out.printf("%tF%n",nn);
        LocalDate nn2 = nn.minusDays(nn.getDayOfMonth()-1);
        System.out.printf("%tF%n",nn2);

        LocalDate n3 = LocalDate.of(2022,3,1);
        System.out.println(n3.getDayOfMonth());

        //获取当前日期本月的最后一天的日期
        var two = LocalDate.of(2022,2,5).with(TemporalAdjusters.lastDayOfMonth());
        System.out.println(two);
        var two2 = LocalDate.of(2022,2,5).with(t -> t.with(DAY_OF_MONTH, t.range(DAY_OF_MONTH).getMaximum()));
        System.out.println(two2);

    }
}
